// https://www.acwing.com/problem/content/838/

#include <iostream>
#include <vector>

using namespace std;

const int MAX_ARRAY_SIZE = 1e5+5;

// 存储每个节点的父节点
int parents[MAX_ARRAY_SIZE];

int find(int x) {
    if (parents[x] != x) {
        parents[x] = find(parents[x]);
    }
    return parents[x];
}

int main() {
    int m, n, a, b;
    char ch;
    cin>>m>>n;
    for (int i=1; i<=m; i++) {
        parents[i] = i;
    }
    while (n-->0) {
        cin>>ch>>a>>b;
        if (ch == 'M') {
            parents[find(a)] = find(b);
        } else {
            if (find(a) == find(b)) {
                cout<<"Yes"<<endl;
            } else {
                cout<<"No"<<endl;
            }
        }
    }

    return 0;
}
